#include "CRL_ShaderProgramAtomic.h"

CB_SUBNAMESPACE_START(RenderLib)

CShaderAtomicPtr IShaderProgramAtomic::GetPass(const char* _pTechnqiueName, const char* _pPassName) const
{
	IdType TechniqueId = m_TechniqueMap.GetId(_pTechnqiueName);
	
	if (TechniqueId == InvalidId) 
		return CShaderAtomicPtr(NULL);
	
	const STechnique& rTechnique = m_Techniques[TechniqueId];
	IdType PassId = rTechnique.m_PassMap.GetId(_pPassName);
	
	if (PassId == InvalidId) 
		return CShaderAtomicPtr(NULL);
	
	return rTechnique.m_Passes[PassId];
}

// ---------------------------------------------------------------------------------------------------------------------

void IShaderProgramAtomic::RegisterPass(IShaderAtomic* _pPass, const char* _pTechnqiueName, const char* _pPassName)
{
	IdType TechniqueId = m_TechniqueMap.RegisterId(_pTechnqiueName);
	
	if (TechniqueId >= (IdType)m_TechniqueMap.Size())
	{
		STechnique NewTechnique;
		m_Techniques.PushBack(NewTechnique);
	}
	
	STechnique& rTechnique = m_Techniques[TechniqueId];
	
	IdType PassId = rTechnique.m_PassMap.RegisterId(_pPassName);
	
	if (PassId >= (IdType)rTechnique.m_Passes.Size())
	{
		CShaderAtomicPtr NewPass(_pPass);
		rTechnique.m_Passes.PushBack(NewPass);
	}
}

CB_SUBNAMESPACE_END